

const http = require('http');
const cheerio = require('cheerio');
const axios = require('axios');
const xlsx = require('node-xlsx');
const fs = require('fs');
const app = http.createServer((req,res)=>{
    axios({
        url:'http://quotes.money.163.com/f10/zycwzb_600519.html#01c01',
    }).then(data=>{
        let $ =  cheerio.load(data.data);
        let arr = [];
        let date = [];
        $('#scrollTable').find('.scr_table tr').eq(11).find('td').each((index,ele)=>{
            arr.push($(ele).text())
        })
        $('#scrollTable').find('.scr_table tr').eq(0).find('th').each((index,ele)=>{
            date.push($(ele).text())
        })
        let xlsxData = [
            {
                name:'净利润(扣除非经常性损益后)(万元)',
                data:[
                    ['报告日期',...date],
                    ['净利润(扣除非经常性损益后)',...arr]
                ]
            }
        ]
        let buffer = xlsx.build(xlsxData);
        fs.writeFileSync('./homework.xlsx',buffer);
    })
    res.end()
})

app.listen('3000',()=>{
    console.log(`start in localhost:3000`)
})






